package com.management.demo.controller.wx;

import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.bean.BeanUtil;
import com.management.demo.domain.wx.Taste;
import com.management.demo.dto.wx.TasteDTO;
import com.management.demo.service.TasteService;
import com.management.demo.vo.wx.TasteVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "口味管理")
@RestController
@RequestMapping("wx/taste")
public class TasteController {

    @Autowired
    private TasteService tasteService;

    @Operation(summary = "查询所有口味")
    @GetMapping("list")
    public SaResult list() {
        List<Taste> tasteList = tasteService.list();
        List<TasteVO> result = BeanUtil.copyToList(tasteList, TasteVO.class);
        return SaResult.ok().setData(result);
    }

    @Operation(summary = "新增/修改口味信息")
    @PostMapping("createOrEdit")
    public SaResult createOrEdit(@RequestBody TasteDTO tasteDTO) {
        Taste taste = BeanUtil.copyProperties(tasteDTO, Taste.class);
        boolean result = tasteService.saveOrUpdate(taste);
        return SaResult.ok().setData(result);
    }

    @Operation(summary = "根据id获取口味信息")
    @GetMapping("getById/{id}")
    public SaResult getById(@Parameter(description = "口味id")
                            @PathVariable Integer id) {
        Taste taste = tasteService.getById(id);
        TasteVO result = BeanUtil.copyProperties(taste, TasteVO.class);
        return SaResult.ok().setData(result);
    }

    @Operation(summary = "删除口味信息")
    @DeleteMapping("remove/{id}")
    public SaResult remove(@Parameter(description = "口味id")
                           @PathVariable Integer id) {
        boolean result = tasteService.removeById(id);
        return SaResult.ok().setData(result);
    }
}
